package cn.congzhou.crm.web.controller;

import cn.congzhou.crm.domain.Customer;
import cn.congzhou.crm.domain.Employee;
import cn.congzhou.crm.query.CustomerQueryObject;
import cn.congzhou.crm.service.ICustomerPoolService;
import cn.congzhou.crm.service.ISystemDictionaryItemService;
import cn.congzhou.crm.utils.UserContext;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Iterator;
import java.util.List;

@Controller
@RequestMapping("/customerPool")
public class CustomerPoolController {

    @Autowired
    private ICustomerPoolService customerPoolService;

    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") CustomerQueryObject qo, Model model) {
        Employee emp = UserContext.getCurrentUser();
//      显示客户池的客户
        qo.setStatus(new Integer[] {Customer.STATUS_POOL});
        PageInfo<Customer> pageInfo = customerPoolService.selectByPage(qo);
        //分页查询
        model.addAttribute("ro",pageInfo);

        return "/customerPool/list";
    }

    @RequestMapping("/queryNewSeller")
    @ResponseBody
    public Object queryNewSeller(){

        List<Employee> employees = customerPoolService.queryNewSeller();
        Employee emp = (Employee) SecurityUtils.getSubject().getPrincipal();
        Iterator<Employee> iterator = employees.iterator();
        //删除自己
        if (iterator.hasNext()){
            if (iterator.next().getId() == emp.getId()) {
                iterator.remove();
            }
        }
        return employees;
    }




}
